#include"comm.h"
#include<unistd.h>

int main()
{
  key_t key = ftok(PATH_NAME, PROJ_ID);
  if(key < 0)
  {
    perror("ftok");
    return 1;
  }

  //client只需要获取
  int shmid = shmget(key, SIZE, IPC_CREAT);
  if(shmid < 0)
  {
    perror("shmget");
    return 2;
  }
  printf("key:0x%x, shmid:%u\n",key, shmid);
  
  char* mem = (char*)shmat(shmid, NULL, 0);
  //sleep(5);
  printf("client attach shm done...\n");

  /*通信*/
  char c = 'a';
  while(c <= 'z')
  {
    sleep(1);
    mem[c-'a'] = c;
    c++;
    mem[c-'a'] = 0;
  }

  shmdt(mem);
  printf("client detach shm done...\n");
  //sleep(5);

  //不需要删除共享内存
  return 0;
}
